Skip to content

fix(examples): bound stdin read so statusline/title scripts can't hang on a held-open pipe - #1501

Open
ai-engineer-devansh-singh wants to merge 1 commit into
google-antigravity:mainfrom
ai-engineer-devansh-singh:fix/example-scripts-stdin-timeout
Open

ai-engineer-devansh-singh wants to merge 1 commit into
google-antigravity:mainfrom
ai-engineer-devansh-singh:fix/example-scripts-stdin-timeout

Conversation

@ai-engineer-devansh-singh

Copy link
Copy Markdown

Fixes #698

Problem

examples/statusline/statusline.sh (via jq) and examples/title/title.sh (via cat) read stdin with no timeout. If the CLI holds the pipe open without writing or closing it, which #698 traces to resume/auth warm-up, the script blocks until the runner kills it (statusline: command failed: signal: killed). After repeated kills, the statusline auto-disables.

There's a second, related failure: if stdin is empty, jq prints nothing and exits 0, so the first read -r STATE fails, and set -e makes statusline.sh exit 1. That also counts as a runner failure.

Change (both scripts)

INPUT=""
IFS= read -r -d '' -t 2 INPUT || true   # read until EOF, give up after 2s
exec 0</dev/null                        # nothing later can block on stdin
[ -n "$INPUT" ] || INPUT='{}'           # timeout/empty -> all fields use defaults

statusline.sh then passes $INPUT to its existing single jq pass with <<<. Apart from that, the parsing and rendering code is unchanged.

The 2s timeout is well under the runner's ~5–10s kill. When the CLI writes the payload and closes the pipe (the normal case), read returns at EOF straight away, so there's no added latency.

Testing

Case Before After
stdin held open, never written (FIFO repro from #698) both scripts killed by an 8s outer timeout (exit 124) exit 0 after 2.0s, default output
Normal JSON payload – byte-identical output to main for both scripts
Payload arrives after 1s, then pipe closes – byte-identical to main
Payload without trailing newline – byte-identical to main
Empty stdin statusline.sh exit 1 exit 0, defaults
Malformed JSON – exit 0, defaults
/dev/null stdin – exit 0
bash 3.2.57 (macOS /bin/bash), in Docker – normal, empty and held-open cases all pass

shellcheck warning count is unchanged for both files.

#699 targets the same issue in statusline.sh only. It uses timeout, or a background sleep + kill fallback, around cat with a 0.25s window. This PR differs in a few ways:

  • It only uses the read -t builtin, so there are no helper processes and nothing depends on timeout being installed.
  • The 2s window gives a slow writer more time; 0.25s could drop a payload that arrives late.
  • It also covers title.sh.
  • It fixes the empty-stdin set -e exit.

🤖 Generated with Claude Code

Both example scripts read stdin with no timeout (`jq` / `cat`). If the
CLI holds the pipe open without writing or closing it (e.g. during resume
or auth warm-up), the script blocks until the runner kills it. Repeated
kills count as failures and auto-disable the statusline.

Read stdin with `read -t 2`, detach stdin afterwards, and fall back to
'{}' on timeout or empty input so every field takes its default. This
also stops statusline.sh from exiting 1 on empty stdin, where `set -e`
tripped on a failed `read`.

Fixes google-antigravity#698
@ai-engineer-devansh-singh

Copy link
Copy Markdown
Author

Tested the patched scripts end-to-end in the real CLI (agy 1.5.5, Ubuntu, bash 5.1):

  • Configured via settings.json and via /statusline <path>: statusline and title render correctly
  • Fresh start, /resume of an existing conversation, and a multi-tool agent turn (15 commands): statusline stayed up, context meter updated live (1.2% → 2.4%), no Statusline disabled warning
  • cli.log shows no statusline/title failures, kills, or timeouts

The held-open-stdin hang from #698 is timing-dependent and didn't occur naturally in these runs. The FIFO repro in the PR description is what demonstrates the fix (before: killed at the timeout; after: exits 0 in 2.0s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Custom statusline script can hang indefinitely on blocked stdin, gets SIGKILL'd, and auto-disables after repeated failures

1 participant